﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Lepton_Practical_MVVM_6_1.Framework;

namespace Lepton_Practical_MVVM_6_1.Models {
    public class MyMenuItem : INotifyPropertyChanged {

        private string _Header;
        /// <summary>
        /// Menu Text
        /// </summary>
        public string Header {
            get {
                return _Header;
            }
            set {
                _Header = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Header"));
            }
        }

        private Uri _IconURI;
        /// <summary>
        /// Menu Icon URI
        /// </summary>
        public Uri IconURI {
            get {
                return _IconURI;
            }
            set {
                _IconURI = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("IconURI"));
            }
        }

        private Type _ViewToOpen;
        /// <summary>
        /// View to open by this menu
        /// </summary>
        public Type ViewToOpen {
            get {
                return _ViewToOpen;
            }
            set {
                _ViewToOpen = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("ViewToOpen"));
            }
        }

        private Type _ViewModelToOpen;
        /// <summary>
        /// ViewModel of View to open
        /// </summary>
        public virtual Type ViewModelToOpen {
            get {
                return _ViewModelToOpen;
            }
            set {
                _ViewModelToOpen = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("ViewModelToOpen"));
            }
        }

        private ObservableCollection<MyMenuItem> _Child
            = new ObservableCollection<MyMenuItem>();
        /// <summary>
        /// 子菜单
        /// </summary>
        public ObservableCollection<MyMenuItem> Child {
            get {
                return _Child;
            }
            set {
                _Child = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Child"));
            }
        }

        private void OpenView(){
            if (ViewToOpen != null) {
                System.Windows.MessageBox.Show("你点击了 " + this.Header);
            }
        }
        private RelayCommand _OpenViewCommand;
        public ICommand OpenViewCommand {
            get {
                if (_OpenViewCommand == null) {
                    _OpenViewCommand = new RelayCommand(x => OpenView());
                }
                return _OpenViewCommand;
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
